﻿using System;

namespace Calendar
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString());
            Console.WriteLine(DateTime.Now.ToLongDateString().ToString());
            Console.WriteLine(new string('-', 30));
            Console.WriteLine(DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月");
            Console.WriteLine("一\t二\t三\t四\t五\t六\t日");
            DateTime dt = DateTime.Now;
            int days = DateTime.DaysInMonth(dt.Year, dt.Month);
            int year = dt.Year;
            int month = dt.Month;
            DateTime firstday = new DateTime(year, month, 1);
            int FirstdayWeekOfMonth = Convert.ToInt32(firstday.DayOfWeek) - 1;//得到本月第一天在第几列
            int daysOfLastMonth = 0;
            if (month == 1)
            {
                daysOfLastMonth = 31;
            }
            else daysOfLastMonth = DateTime.DaysInMonth(year, (month - 1));//得到上一个月的天数
            Console.ForegroundColor = ConsoleColor.DarkGray;
            for ( int j = 7 - FirstdayWeekOfMonth; j >= 0; j --)
            {
                Console.Write( daysOfLastMonth - j + "\t");
            }
            int PlaceofDay = FirstdayWeekOfMonth;//输出上个月日历部分
            for ( int k = 1; k <= days; k ++)
            {
                if ( k != DateTime.Now.Day)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write(k + "\t");
                PlaceofDay++;
                if ( PlaceofDay == 7)
                {
                    Console.WriteLine();
                    PlaceofDay = 0;
                }
                else continue;
            }//输出本月日历部分
            Console.ForegroundColor = ConsoleColor.DarkGray;
            if ( PlaceofDay == 6)
            {
                Console.WriteLine();
                int m = 1;
                do
                {
                    Console.Write(m + "\t");
                    m++;
                }
                while (m <= 7);
            }
            else
            {
                int m = 1;
                for ( int n = PlaceofDay; n <= 6; n++)
                {
                    Console.Write(m + "\t");
                    m++;
                }
            }//输出下个月日历部分
            Console.ForegroundColor = ConsoleColor.White;
        }
    }
}
